<template>
	<view class="my-cartbox">
		<!-- 结算组件 -->
		<view class="jiesuan">
			<view class="lift">
				<radio @click="haoozhuangt" :checked="state" color="#C00000"></radio>
				<view class="checke">全选</view>
			</view>
			<view class="zhobu">
				<view class="heji">合计:</view>
				<view class="parci">{{prlce | RMBformat}}</view>
			</view>
			<view class="right" @click="settlement">结算({{sumo}})</view>
		</view>
	</view>
</template>

<script>
import { mapGetters, mapState } from 'vuex'
	export default {
		name:"my-settle",
		data() {
			return {
				ishow:true,
				vulet:4,
				goods:[]
			};
		},
		computed:{
			//总价，选中的商品
			...mapGetters(['prlce','sumo','state']),
			...mapState({cartAddress:state=>state.cart.cartAddress,token:state=>state.user.token,datalist:state=>state.cart.cartData})
		},
		methods:{
			//全选状态点击事件
			haoozhuangt(){
				this.$store.commit('zhuangtbh',this.state)
			},
			//自动跳到登录页
			addlogingo(){
				let semr = null
				semr = setInterval(()=>{
					this.vulet --
					this.gettoshow(this.vulet)
					if(this.vulet <= 0){
						this.vulet = 4
						clearInterval(semr)
						uni.switchTab({
							url:'/pages/my/my',
							//页面跳转完成执行的回调，保存当前页面路径信息，方便登录后根据储存的路径进行回跳过来
							success:()=>{
								let obj = {openType:'switchTab',from:'/pages/cart/cart'}
								this.$store.commit('addrouters',obj)
							}
						})
					}
				},1000)
			},
			//结算事件
			settlement(){
				//判断有没有填写地址
				if(!this.cartAddress.userName){
					uni.showToast({
						title:'请填写地址~',
						icon:'error'
					})
					return
				}
				//判断有没有选择商品
				if(this.sumo < 1){
					uni.showToast({
						title:'你还未勾选商品',
						icon:'error'
					})
					return
				}
				//判断用户有没有登录
				if(!this.token){
					this.addlogingo()
					return
				}
				this.goods = this.datalist.filter(item=> {return item.goods_state}).map(item=>{return {
					id:item.goods_id,
					nuber:item.goods_count,
					prier:item.goods_price
				}})
				console.log(this.goods)
			},
			//未登录提示框
			gettoshow(vulet){
				if(vulet == 0) return
				uni.showToast({
					title:'请登录后再结算'+ vulet +'后跳到登录页',
					icon:'none',
					mask:true,
					duration:1000
				})
			}
		},
		watch:{
			cartAddress(){
				if(this.cartAddress){
					this.ishow = true
					console.log(this.ishow)
				}else{
					this.ishow = false
					console.log(this.ishow)
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
.my-cartbox{
	position: fixed;
	left: 0;
	bottom: 0;
	width: 100%;
	height: 50px;
	background-color: #dcdcdc;
	z-index: 999;
	.jiesuan{
		padding: 0 5px;
		padding-right: 0;
		line-height: 50px;
		text-align: center;
		display: flex;
		align-items: center;
		justify-content: space-between;
		.lift{
			display: flex;
			align-items: center;
		}
		.zhobu{
			display: flex;
			align-items: center;
			.parci{
				margin-left: 5px;
				color:#C00000 ;
			}
		}
		.right{
			width: 100px;
			height: 50px;
			line-height: 50px;
			text-align: center;
			background: #C00000;
			color: #FFFFFF;
		}
	}
}
</style>
